package com.bigflexlib.x.Object
{
	/**
	 * 
	 * 
	 * 
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class ObjectClipboard
	{
			
		private var propertyNames:Array;
		private var clipboard:Object = {};

		/**
		 * 
		 * @param propertyNames
		 * @return 
		 * 
		 */
		public function ObjectClipboard( propertyNames:Array = null )
		{
			this.propertyNames = propertyNames;
		}
		
		/**
		 * 
		 * Copy explicit properties
		 * or all enumerable properties if no explicit propertyNames were passed
		 * 
		 * @param sourceObject
		 * 
		 */		
		public function copy( source:Object ):void
		{
			var name:String;
			if ( propertyNames == null ) // copy all enumerable properties
				for ( name in source )
					clipboard[ name ] = source[ name ];
			else
				for each ( name in propertyNames ) // copy specified properties
					clipboard[ name ] = source[ name ];
		}


		/**
		 * 
		 * 
		 * 
		 * @param target
		 * 
		 */
		public function paste( target:Object ):void
		{
			for ( var name:String in clipboard )
				target[ name ] = clipboard[ name ];				
		}
		
		/**
		 * 
		 * If you keep a strong reference to this Clipboard object
		 * remember to call this function once you are ready to clear the internal storage
		 * 
		 */		
		public function clear():void
		{
			this.clipboard = new Object(); // release reference to allow garbage collection	
		}

	}

}